package cn.edu.neusoft.amicooldemo.model;

import java.util.List;

import cn.edu.neusoft.amicooldemo.bean.ArticleBean;
import cn.edu.neusoft.amicooldemo.bean.ProjectBean;
import cn.edu.neusoft.amicooldemo.bean.SVideoBean;
import cn.edu.neusoft.amicooldemo.bean.TcaseBean;
import cn.edu.neusoft.amicooldemo.bean.TwareBean;
import cn.edu.neusoft.amicooldemo.bean.VideoBean;
import cn.edu.neusoft.amicooldemo.iface.AmicoolIface;
import cn.edu.neusoft.amicooldemo.iface.AmicoolListener;
import cn.edu.neusoft.amicooldemo.service.AmicoolService;
import retrofit2.Call;

/**
 * Created by Neusoft on 2016/12/21.
 */

public class AmicoolModel<T> extends BaseModel implements AmicoolIface<T> {
    private AmicoolService service;
    private static AmicoolModel model;


    public AmicoolModel(){
        super();
    }
    public static AmicoolModel getInstance(){
        if(model==null){
            model = new AmicoolModel();

        }
        return model;
    }

   /* @Override
    public void getResultList(String mod,final int page, String sessionID, final AmicoolListener<ArticleBean> listener) {
        service = createService(ArticleService.class);
        Call<List<ArticleBean>> call = service.getResultList(mod,page,sessionID);
        call.enqueue(new Callback<List<ArticleBean>>() {
            @Override
            public void onResponse(Call<List<ArticleBean>> call, Response<List<ArticleBean>> response) {
                if(response.body()!=null&&response.body().size()!=0){
                    if(page==1)
                        listener.onResponse( response.body());
                    else
                        listener.loadNextData(response.body());
                }
            }

            @Override
            public void onFailure(Call<List<ArticleBean>> call, Throwable t) {

            }
        });
    }*/

    @Override
    public void getResultList(String mod, int page, String sessionID, AmicoolListener<T> listener) {
        service = createService(AmicoolService.class);
        switch (mod) {
            case "video":
                Call<List<VideoBean>> call = service.getVideoList(mod,page,sessionID);
                call.enqueue(new CallbackAmicool<VideoBean>(page, listener));
                break;
            case "svideo":
                Call<List<SVideoBean>> call1 = service.getSVideoList("video",page,sessionID);
                call1.enqueue(new CallbackAmicool<SVideoBean>(page, listener));
                break;
            case "article":
                Call<List<ArticleBean>> call2 = service.getArticleList(mod,page,sessionID);
                call2.enqueue(new CallbackAmicool<ArticleBean>(page, listener));
                break;
            case "tware":
                Call<List<TwareBean>> call3 = service.getTwareList(mod,page,sessionID);
                call3.enqueue(new CallbackAmicool<TwareBean>(page, listener));
                break;
            case "tcase":
                Call<List<TcaseBean>> call4 = service.getTcaseList(mod,page,sessionID);
                call4.enqueue(new CallbackAmicool<TcaseBean>(page, listener));
                break;
            case "project":
                Call<List<ProjectBean>> call5 = service.getProjectList(mod,page,sessionID);
                call5.enqueue(new CallbackAmicool<ProjectBean>(page, listener));
                break;


        }
    }

    @Override
    public void getResultBean(String mod, int id, String sessionID, AmicoolListener<T> listener) {

    }
}
